#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll rr() {
    ll s = 0, w = false, c = getchar();
    for (; !isdigit(c); c = getchar())
        w = w || c == '-';
    for (; isdigit(c); c = getchar())
        s = s * 10 + c - '0';
    return w ? -s : s;
}

// END OF HEADER

int main() {
    int n = rr(), c = rr();
    vector<int> dp(c + 1);
    for (int i = 0; i < n; i++) {
        int wi = rr(), vi = rr();
        for (int j = c; j >= wi; j--)
            dp[j] = max(dp[j], dp[j - wi] + vi);
    }
    printf("%d", dp[c]);
    return 0;
}
